<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: Rails::Generator::Lookup::ClassMethods</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">Rails::Generator::Lookup::ClassMethods</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../../files/vendor/rails/railties/lib/rails_generator/lookup_rb.html">
                vendor/rails/railties/lib/rails_generator/lookup.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M001534">append_sources</a>&nbsp;&nbsp;
      <a href="#M001540">instance</a>&nbsp;&nbsp;
      <a href="#M001539">lookup</a>&nbsp;&nbsp;
      <a href="#M001535">prepend_sources</a>&nbsp;&nbsp;
      <a href="#M001536">reset_sources</a>&nbsp;&nbsp;
      <a href="#M001533">sources</a>&nbsp;&nbsp;
      <a href="#M001537">use_application_sources!</a>&nbsp;&nbsp;
      <a href="#M001538">use_component_sources!</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M001534" class="method-detail">
        <a name="M001534"></a>

        <div class="method-heading">
          <a href="#M001534" class="method-signature">
          <span class="method-name">append_sources</span><span class="method-args">(*args)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Add a source to the end of the list.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001534-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001534-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/lookup.rb, line 68</span>
68:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">append_sources</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
69:           <span class="ruby-identifier">sources</span>.<span class="ruby-identifier">concat</span>(<span class="ruby-identifier">args</span>.<span class="ruby-identifier">flatten</span>)
70:           <span class="ruby-identifier">invalidate_cache!</span>
71:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001540" class="method-detail">
        <a name="M001540"></a>

        <div class="method-heading">
          <a href="#M001540" class="method-signature">
          <span class="method-name">instance</span><span class="method-args">(generator_name, args = [], runtime_options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Convenience method to <a href="ClassMethods.html#M001539">lookup</a> and
instantiate a generator.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001540-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001540-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/lookup.rb, line 135</span>
135:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">instance</span>(<span class="ruby-identifier">generator_name</span>, <span class="ruby-identifier">args</span> = [], <span class="ruby-identifier">runtime_options</span> = {})
136:           <span class="ruby-identifier">lookup</span>(<span class="ruby-identifier">generator_name</span>).<span class="ruby-identifier">klass</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">args</span>, <span class="ruby-identifier">full_options</span>(<span class="ruby-identifier">runtime_options</span>))
137:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001539" class="method-detail">
        <a name="M001539"></a>

        <div class="method-heading">
          <a href="#M001539" class="method-signature">
          <span class="method-name">lookup</span><span class="method-args">(generator_name)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
<a href="../Lookup.html">Lookup</a> knows how to find generators&#8217;
Specs from a list of Sources. Searches the <a
href="ClassMethods.html#M001533">sources</a>, in order, for the first
matching name.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001539-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001539-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/lookup.rb, line 120</span>
120:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">lookup</span>(<span class="ruby-identifier">generator_name</span>)
121:           <span class="ruby-ivar">@found</span> <span class="ruby-operator">||=</span> {}
122:           <span class="ruby-identifier">generator_name</span> = <span class="ruby-identifier">generator_name</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">downcase</span>
123:           <span class="ruby-ivar">@found</span>[<span class="ruby-identifier">generator_name</span>] <span class="ruby-operator">||=</span> <span class="ruby-identifier">cache</span>.<span class="ruby-identifier">find</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">spec</span><span class="ruby-operator">|</span> <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">generator_name</span> }
124:           <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@found</span>[<span class="ruby-identifier">generator_name</span>] 
125:             <span class="ruby-identifier">chars</span> = <span class="ruby-identifier">generator_name</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp re">/./</span>).<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span><span class="ruby-node">&quot;#{c}.*?&quot;</span>}
126:             <span class="ruby-identifier">rx</span> = <span class="ruby-node">/^#{chars}$/</span>
127:             <span class="ruby-identifier">gns</span> = <span class="ruby-identifier">cache</span>.<span class="ruby-identifier">select</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">spec</span><span class="ruby-operator">|</span> <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">=~</span> <span class="ruby-identifier">rx</span> }
128:             <span class="ruby-ivar">@found</span>[<span class="ruby-identifier">generator_name</span>] <span class="ruby-operator">||=</span> <span class="ruby-identifier">gns</span>.<span class="ruby-identifier">first</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">gns</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
129:             <span class="ruby-identifier">raise</span> <span class="ruby-constant">GeneratorError</span>, <span class="ruby-node">&quot;Pattern '#{generator_name}' matches more than one generator: #{gns.map{|sp|sp.name}.join(', ')}&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">gns</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>
130:           <span class="ruby-keyword kw">end</span>
131:           <span class="ruby-ivar">@found</span>[<span class="ruby-identifier">generator_name</span>] <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">GeneratorError</span>, <span class="ruby-node">&quot;Couldn't find '#{generator_name}' generator&quot;</span>
132:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001535" class="method-detail">
        <a name="M001535"></a>

        <div class="method-heading">
          <a href="#M001535" class="method-signature">
          <span class="method-name">prepend_sources</span><span class="method-args">(*args)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Add a source to the beginning of the list.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001535-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001535-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/lookup.rb, line 74</span>
74:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">prepend_sources</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
75:           <span class="ruby-identifier">write_inheritable_array</span>(<span class="ruby-identifier">:sources</span>, <span class="ruby-identifier">args</span>.<span class="ruby-identifier">flatten</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">sources</span>)
76:           <span class="ruby-identifier">invalidate_cache!</span>
77:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001536" class="method-detail">
        <a name="M001536"></a>

        <div class="method-heading">
          <a href="#M001536" class="method-signature">
          <span class="method-name">reset_sources</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Reset the source list.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001536-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001536-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/lookup.rb, line 80</span>
80:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reset_sources</span>
81:           <span class="ruby-identifier">write_inheritable_attribute</span>(<span class="ruby-identifier">:sources</span>, [])
82:           <span class="ruby-identifier">invalidate_cache!</span>
83:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001533" class="method-detail">
        <a name="M001533"></a>

        <div class="method-heading">
          <a href="#M001533" class="method-signature">
          <span class="method-name">sources</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
The list of <a href="ClassMethods.html#M001533">sources</a> where we look,
in order, for generators.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001533-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001533-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/lookup.rb, line 63</span>
63:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sources</span>
64:           <span class="ruby-identifier">read_inheritable_attribute</span>(<span class="ruby-identifier">:sources</span>) <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">use_component_sources!</span>
65:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001537" class="method-detail">
        <a name="M001537"></a>

        <div class="method-heading">
          <a href="#M001537" class="method-signature">
          <span class="method-name">use_application_sources!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Use application generators (app, ?).
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001537-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001537-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/lookup.rb, line 86</span>
86:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">use_application_sources!</span>
87:           <span class="ruby-identifier">reset_sources</span>
88:           <span class="ruby-identifier">sources</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">PathSource</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">:builtin</span>, <span class="ruby-node">&quot;#{File.dirname(__FILE__)}/generators/applications&quot;</span>)
89:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001538" class="method-detail">
        <a name="M001538"></a>

        <div class="method-heading">
          <a href="#M001538" class="method-signature">
          <span class="method-name">use_component_sources!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Use component generators (model, controller, etc).
</p>
<ol>
<li><a href="../../../Rails.html">Rails</a> application. If RAILS_ROOT is
defined we know we&#8216;re generating in the context of a <a
href="../../../Rails.html">Rails</a> application, so search
RAILS_ROOT/generators.

</li>
<li>Look in plugins, either for generators/ or rails_generators/ directories
within each plugin

</li>
<li>User home directory. Search ~/.rails/generators.

</li>
<li>RubyGems. Search for gems named *_generator, and look for generators within
any RubyGem&#8216;s /rails_generators/&lt;generator_name&gt;_generator.rb
file.

</li>
<li>Builtins. Model, controller, mailer, scaffold, and so on.

</li>
</ol>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001538-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001538-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/lookup.rb, line 102</span>
102:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">use_component_sources!</span>
103:           <span class="ruby-identifier">reset_sources</span>
104:           <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">defined?</span> <span class="ruby-operator">::</span><span class="ruby-constant">RAILS_ROOT</span>
105:             <span class="ruby-identifier">sources</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">PathSource</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">:lib</span>, <span class="ruby-node">&quot;#{::RAILS_ROOT}/lib/generators&quot;</span>)
106:             <span class="ruby-identifier">sources</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">PathSource</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">:vendor</span>, <span class="ruby-node">&quot;#{::RAILS_ROOT}/vendor/generators&quot;</span>)
107:             <span class="ruby-identifier">sources</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">PathSource</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">:plugins</span>, <span class="ruby-node">&quot;#{::RAILS_ROOT}/vendor/plugins/*/**/generators&quot;</span>)
108:             <span class="ruby-identifier">sources</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">PathSource</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">:plugins</span>, <span class="ruby-node">&quot;#{::RAILS_ROOT}/vendor/plugins/*/**/rails_generators&quot;</span>)
109:           <span class="ruby-keyword kw">end</span>
110:           <span class="ruby-identifier">sources</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">PathSource</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">:user</span>, <span class="ruby-node">&quot;#{Dir.user_home}/.rails/generators&quot;</span>)
111:           <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Object</span>.<span class="ruby-identifier">const_defined?</span>(<span class="ruby-identifier">:Gem</span>)
112:             <span class="ruby-identifier">sources</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">GemGeneratorSource</span>.<span class="ruby-identifier">new</span>
113:             <span class="ruby-identifier">sources</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">GemPathSource</span>.<span class="ruby-identifier">new</span>
114:           <span class="ruby-keyword kw">end</span>
115:           <span class="ruby-identifier">sources</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">PathSource</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">:builtin</span>, <span class="ruby-node">&quot;#{File.dirname(__FILE__)}/generators/components&quot;</span>)
116:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>